package com.qnw.CardGroupManagement.adapter;

import android.content.*;
import android.view.*;
import android.widget.*;
import java.util.*;
import com.ygo.feihua.*;
import android.graphics.*;
import com.qnw.CardGroupManagement.management.*;

public class AdapterCdb extends BaseAdapter
{

	private List<Map<String,Object>> data=new ArrayList<Map<String,Object>>();
	private Context context;

	private boolean selected=false;
	CdbManagement cm;
	
	
	public AdapterCdb(Context context ,List<Map<String,Object>> data){
		this.context=context;
		this.data=data;
		cm=CdbManagement.getdx();
	}
	
	Zujian zujian;

	public void setSelected(boolean selected)
	{
		this.selected = selected;
		notifyDataSetChanged();
	}

	public boolean isSelected()
	{
		return selected;
	}
	
	class Zujian{
		RelativeLayout cdb_lin;
		TextView cdb_name;
		CheckBox cdb_ch;
	}
	
	@Override
	public int getCount()
	{
		// TODO: Implement this method
		return data.size();
	}

	@Override
	public Object getItem(int p1)
	{
		// TODO: Implement this method
		return data.get(p1);
	}

	@Override
	public long getItemId(int p1)
	{
		// TODO: Implement this method
		return p1;
	}

	@Override
	public View getView(int position, View p2, ViewGroup p3)
	{
		if(p2==null){
			zujian=new Zujian();
			p2=LayoutInflater.from(context).inflate(R.layout.item_cdb,null);
			zujian.cdb_name=(TextView) p2.findViewById(R.id.cdb_name);
			zujian.cdb_lin= (RelativeLayout) p2.findViewById(R.id.cdb_lin);
			zujian.cdb_ch=(CheckBox) p2.findViewById(R.id.cdb_ch);
			p2.setTag(zujian);
			
		}else{
			zujian=(AdapterCdb.Zujian) p2.getTag();
		}
		zujian.cdb_name.setText((String)data.get(position).get("name"));
		
		if((boolean)data.get(position).get("dq")){
			zujian.cdb_lin.setBackgroundColor(Color.parseColor("#c6c6c6"));
		}else{
			zujian.cdb_lin.setBackgroundColor(Color.parseColor("#ffffff"));
		}
		String path=(String) data.get(position).get("path");
		
		if(selected){
			if(position!=data.size()-1){
			zujian.cdb_ch.setVisibility(View.VISIBLE);

			if(cm.getXzcdb().contains(path)){
				zujian.cdb_ch.setChecked(true);
			}else{
				zujian.cdb_ch.setChecked(false);
			}
			}else{
			zujian.cdb_ch.setVisibility(View.GONE);
			}
		}else{
			cm.getXzcdb().clear();
			zujian.cdb_ch.setVisibility(View.GONE);
		}
		
		
		// TODO: Implement this method
		return p2;
	}
	
	
	
}
